Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XFuNTreeNode.h

Go to the documentation of this file.
00001 /*! \file 
00002  * X-Forge Util <br>
00003  * Copyright 2000-2003 Fathammer Ltd
00004  * 
00005  * \brief N-tree node template 
00006  * 
00007  * $Id: XFuNTreeNode.h,v 1.6 2003/03/20 13:19:59 jetro Exp $
00008  * $Date: 2003/03/20 13:19:59 $
00009  * $Revision: 1.6 $
00010  */
00011 
00012 #ifndef XFUNTREENODE_H_INCLUDED
00013 #define XFUNTREENODE_H_INCLUDED
00014 
00015 template<class T> class XFuNTree;
00016 
00017 
00018 template<class T> class XFuNTreeNode
00019 {
00020 public:
00021     //! Returns the amount of allocated child nodes.
00022     /*!
00023      * \return Amount of allocated child nodes.
00024      */
00025     UINT32 size() const;
00026 
00027     //! Returns information about the validity of the Nth child node.
00028     /*!
00029      * \param aIndex Index of child node.
00030      * \return 1 if the node is not NULL, 0 otherwise.
00031      */
00032     INT isValid(const UINT32 aIndex) const;
00033     
00034     //! Checks whether the node is a leaf node.
00035     /*!
00036      * \return 1 if the node is a leaf node, 0 otherwise.
00037      */
00038     INT isLeaf() const;
00039 
00040     //! Returns pointer to Nth child node.
00041     /*!
00042      * \return Pointer to the Nth child node.
00043      */
00044     XFuNTreeNode<T> * getChild(const UINT32 aIndex);
00045 
00046     //! Sets the internal data of the node.
00047     /*!
00048      * \param aNewData Data to be set.
00049      */
00050     void setData(const T aNewData);
00051     
00052     //! Returns the internal data of the node.
00053     /*!
00054      * \return Internal data of the node.
00055      */
00056     T getData() const;
00057 
00058     //! Creates an empty node.
00059     XFuNTreeNode(const UINT32 aChildNodes);
00060     //! Creates a node with internal data.
00061     /*!
00062      * \param aNewData Data to be set.
00063      */
00064     XFuNTreeNode(const UINT32 aChildNodes, const T aNewData);
00065 
00066     //! Destructor.
00067     ~XFuNTreeNode();
00068     
00069 protected:
00070     
00071     UINT32 mIndexInParent;
00072 
00073     UINT32 mChildNodes;
00074     UINT32 mAllocatedChildNodes;
00075 
00076     T mData;
00077 
00078     XFuNTreeNode<T> *mParent;
00079     XFuNTreeNode<T> **mChildren;
00080 
00081     friend class XFuNTree<T>;
00082 };
00083 
00084 
00085 template<class T> UINT32 XFuNTreeNode<T>::size() const
00086 {
00087     return mAllocatedChildNodes;
00088 }
00089 
00090 
00091 template<class T> INT XFuNTreeNode<T>::isValid(const UINT32 aIndex) const
00092 {
00093     if (mChildren[aIndex] != NULL)
00094         return 1;
00095     else
00096         return 0;
00097 }
00098 
00099 
00100 template<class T> INT XFuNTreeNode<T>::isLeaf() const
00101 {
00102     UINT32 i;
00103 
00104     for (i = 0; i < mChildNodes; ++i)
00105     {
00106         if (mChildren[i] != NULL)
00107             return 0;
00108     }
00109 
00110     return 1;
00111 }
00112 
00113 
00114 template<class T> 
00115 XFuNTreeNode<T> * XFuNTreeNode<T>::getChild(const UINT32 aIndex)
00116 {
00117     if (aIndex < mChildNodes)
00118         return mChildren[aIndex];
00119     else
00120         return NULL;
00121 }
00122 
00123 
00124 template<class T> void XFuNTreeNode<T>::setData(const T aNewData)
00125 {
00126     mData = aNewData;
00127 }
00128 
00129 
00130 template<class T> T XFuNTreeNode<T>::getData() const
00131 {
00132     return mData;
00133 }
00134 
00135 
00136 template<class T> XFuNTreeNode<T>::XFuNTreeNode(const UINT32 aChildNodes)
00137 {
00138     mParent = NULL;
00139 
00140     mChildNodes = aChildNodes;
00141     mChildren = new XFuNTreeNode<T> *[aChildNodes];
00142     mAllocatedChildNodes = 0;
00143 
00144     UINT32 i;
00145     for (i = 0; i < mChildNodes; ++i)
00146     {
00147         mChildren[i] = NULL;
00148     }
00149 }
00150 
00151 
00152 template<class T> XFuNTreeNode<T>::XFuNTreeNode(const UINT32 aChildNodes, 
00153                                                 const T aNewData)
00154 {
00155     mParent = NULL;
00156 
00157     mData = aNewData;
00158     mChildNodes = aChildNodes;
00159     mChildren = new XFuNTreeNode<T> *[aChildNodes];
00160     mAllocatedChildNodes = 0;
00161 
00162     UINT32 i;
00163     for (i = 0; i < mChildNodes; ++i)
00164     {
00165         mChildren[i] = NULL;
00166     }
00167 }
00168 
00169 
00170 template<class T> XFuNTreeNode<T>::~XFuNTreeNode()
00171 {
00172     UINT32 i;
00173     for (i = 0; i < mChildNodes; ++i)
00174     {
00175         delete mChildren[i];
00176         mAllocatedChildNodes--;
00177     }
00178 
00179     delete[] mChildren;
00180 }
00181 
00182 
00183 #endif // !XFUNTREENODE_H_INCLUDED

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch